<template>
  <div class="tx-log-con">
    <div v-show="txLog.length>0">
      <van-list
        v-model="loading"
        :finished="finished"
        :error.sync="error"
        error-text="请求失败，点击重新加载"
        finished-text=""
        @load="onLoad"
      >
        <div class="supplier_widthdraw_detail" v-for="(item,index) in txLog" :key="index">
          <p>
            <span>申请时间：</span>
            {{item.apply_time}}
          </p>
          <div class="flx">
            <p class="w50">
              <span>申请金额：</span>
              <i v-html="item.money"></i>
            </p>
            <p class="w50">
              <span>收款人：</span>
              {{item.payee}}
            </p>
          </div>
          <p>
            <span>申请状态：</span>
            <span class="gray" v-if="item.have_pay == 0">待审核</span>
            <span class="yellow" v-if="item.have_pay == 1">已审核</span>
            <span class="green" v-if="item.have_pay == 2">已发放</span>
            <span class="red" v-if="item.have_pay == 3">驳回</span>
          </p>
          <p v-if="item.have_pay == 3 && item.reason">
            <span>驳回理由：</span>{{ item.reason }}
          </p>
        </div>
        <!-- <div v-for="(txItem,index) in txLog" :key="index" class="item-li">
          <span class="num">
            <i>&yen;</i>
            {{txItem.change_num}}
          </span>
          <p class="log-info" v-if="txItem.status==3 && txItem.reason">
            {{txItem.status_name}}&nbsp;&nbsp;理由：{{txItem.reason}}
            <a
              href="javascript:;"
              class="cancle-btn"
              @click="cancelTx(txItem.user_balance_id)"
              v-if="txItem.status==0 && txItem.show_cancle==0"
            >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;取消申请</a>
          </p>
          <p class="log-info" v-else>
            {{txItem.status_name}}
            <a
              href="javascript:;"
              class="cancle-btn"
              @click="cancelTx(txItem.user_balance_id)"
              v-if="txItem.status==0 && txItem.show_cancle==0"
            >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;取消申请</a>
          </p>
          <p class="time">{{txItem.create_time}}</p>
        </div>-->
      </van-list>
    </div>
    <div v-show="!txLog.length && finished">
      <no-data :noData="noData"></no-data>
    </div>
  </div>
</template>

<script>
import Vue from 'vue'
import { getWithdrawList } from '@/api/user/gys/gysApi'
import noData from '@/components/noData/index'
export default Vue.extend({
  name: 'index',
  components: {
    noData
  },
  data() {
    return {
      noData: {
        img: 'https://img.wifenxiao.com/h5-wfx/images/user/no_tx_log.png',
        text: '暂无提现记录'
      },
      page: 1,
      txLog: [],
      error: false,
      loading: false,
      finished: false,
      isload: false
    }
  },
  props: {
    listPage: {
      type: Number,
      default: 0
    }
  },
  watch: {
    'listPage': {
      handler(val) {
        if (val == 1) {
          this.page = 1
          this.isload = false
          this.finished = false
          this.onLoad()
        }
      },
      deep: true
    }
  },
  methods: {
    init() {
      this.$loadingWrap.show()
      setTimeout(() => {
        this.$loadingWrap.close()
      }, 50000)
      this.onLoad()
    },
    onLoad() {
      const params = {
        // act_type: true,
        p: this.page
      }
      if (this.isload && this.page == 1){
        this.finished = true
        return
      }
      if (this.finished) {
        return
      }
      getWithdrawList(params)
        .then(res => {
          this.loading = false
          this.$loadingWrap.close()
          if (res.status == 1) {
            this.$emit('changeListPage', 0)
            const resData = res.data
            this.isload = true
            if (this.page == 1) {
              this.txLog = resData.data
            } else {
              this.txLog.push(...resData.data)
            }
            if (resData.data.length < 10) {
              this.finished = true
            } else {
              this.page++
            }
          } else {
            this.$Error(res.msg)
          }
        })
        .catch(() => {
          this.error = true
        })
    },
    cancelTx(id) {
      this.$emit('cancelTx', id)
    }
  },
  created() {
    this.init()
  }
})
</script>

<style lang="scss">
.tx-log-con {
  .supplier_widthdraw_detail {
    position: relative;
    z-index: 11;
    border-bottom: 2px solid #dcdcdc;
    padding: 20px 0;
    font-size: 28px;
    margin: 0 20px;
    .flx {
      display: flex;
    }
    p {
      line-height: 60px;
      width: 100%;
      color: #999;
      font-size: 26px;
      word-wrap: break-word;
      word-break: break-all;
      &.w50 {
        width: 50%;
      }
      span {
        color: #ff8c10;
        font-size: 28px;
        margin-right: 16px;
        &.gray {
          color: #999;
        }
        &.yellow {
          color: #ff8c10;
        }
        &.green {
          color: #21e900;
        }
        &.red {
          color: red;
        }
      }
    }
  }
  // margin: 0 20px;
  // text-align: center;
  // .tr {
  //   display: -webkit-box;
  //   display: -webkit-flex;
  //   display: flex;
  //   -webkit-flex-wrap: wrap;
  //   flex-wrap: wrap;
  //   .td {
  //     flex-basis: 33.3333%;
  //     flex-basis: 1;
  //     &:nth-child(1) {
  //       flex: 1;
  //     }
  //     &:nth-child(2) {
  //       flex: 1;
  //     }
  //     &:nth-child(3) {
  //       flex: 2;
  //     }
  //     &.no-data {
  //       color: #666;
  //     }
  //   }
  // }
  // .thead {
  //   font-weight: 500;
  //   background: #f4f4f4;
  //   .td {
  //     padding: 20px 0;
  //     color: #000;
  //   }
  // }
  // .tbody {
  //   .td {
  //     padding: 30px 0;
  //     &:nth-child(1) {
  //       color: #ff7200;
  //     }
  //     &:nth-child(2) {
  //       color: #333;
  //     }
  //     &:nth-child(3) {
  //       color: #666;
  //     }
  //   }
  // }
}
</style>
